var e, t, a = require("../../@babel/runtime/helpers/interopRequireDefault"), r = a(require("../../@babel/runtime/regenerator")), n = require("../../@babel/runtime/helpers/asyncToGenerator"), s = a(require("../../utils/api")), i = getApp();

Page({
    data: {
        statusBarHeight: i.globalData.statusBarHeight,
        resourceUrl: i.globalData.resourceUrl,
        name: "",
        isParty: !1,
        rankImg: null,
        headImg: "",
        companyName: "",
        score: "",
        restMemberScore: "",
        dailyActive: !1,
        passActive: !1,
        pkActive: !1,
        activities: [],
        signDays: 0,
        cardSum: null
    },
    getUserInfo: function() {
        var e = this;
        return n(r.default.mark(function t() {
            var a, n, o;
            return r.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return a = wx.getStorageSync("openid"), t.prev = 1, t.next = 4, s.default.userInfo({
                        openid: a
                    });

                  case 4:
                    n = t.sent, o = n.result.memberScore, i.globalData.scoreboard = o, i.globalData.restMemberScore = n.result.restMemberScore, 
                    e.setData({
                        score: o,
                        restMemberScore: n.result.restMemberScore,
                        name: i.globalData.userInfo.name,
                        isParty: n.result.isParty,
                        rankImg: n.result.gradeImage,
                        headImg: i.globalData.userInfo.headImg,
                        companyName: i.globalData.userInfo.companyName
                    }), t.next = 14;
                    break;

                  case 11:
                    t.prev = 11, t.t0 = t.catch(1), console.log(t.t0.msg);

                  case 14:
                  case "end":
                    return t.stop();
                }
            }, t, null, [ [ 1, 11 ] ]);
        }))();
    },
    getSignList: (t = n(r.default.mark(function e() {
        var t, a;
        return r.default.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return t = wx.getStorageSync("openid"), e.prev = 1, e.next = 4, s.default.signList({
                    openid: t
                });

              case 4:
                a = e.sent, this.setData({
                    signDays: a.result.signDays
                }), e.next = 11;
                break;

              case 8:
                e.prev = 8, e.t0 = e.catch(1), console.log(e.t0);

              case 11:
              case "end":
                return e.stop();
            }
        }, e, this, [ [ 1, 8 ] ]);
    })), function() {
        return t.apply(this, arguments);
    }),
    getCardInfo: function() {
        var e = this;
        return n(r.default.mark(function t() {
            var a, n, i;
            return r.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return a = wx.getStorageSync("openid"), t.prev = 1, t.next = 4, s.default.getCardDetail({
                        openid: a
                    });

                  case 4:
                    n = t.sent, i = n.result, e.setData({
                        cardSum: i
                    }), t.next = 12;
                    break;

                  case 9:
                    t.prev = 9, t.t0 = t.catch(1), console.log(t.t0.msg);

                  case 12:
                  case "end":
                    return t.stop();
                }
            }, t, null, [ [ 1, 9 ] ]);
        }))();
    },
    getAnswer: function() {
        var e = this;
        return n(r.default.mark(function t() {
            var a, n, o;
            return r.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return a = wx.getStorageSync("openid"), t.prev = 1, t.next = 4, s.default.userStatus({
                        openid: a
                    });

                  case 4:
                    return n = t.sent, t.next = 7, s.default.activityList({
                        openid: a
                    });

                  case 7:
                    o = t.sent, e.setData({
                        dailyActive: n.result.dayActive,
                        passActive: n.result.gameActive,
                        pkActive: n.result.pkActive,
                        activities: o.result.list
                    }), i.globalData.dailyTimeLimit = n.result.dayInterval, i.globalData.passTimeLimit = n.result.gameInterval, 
                    i.globalData.pkTimeLimit = n.result.pkInterval, t.next = 17;
                    break;

                  case 14:
                    t.prev = 14, t.t0 = t.catch(1), console.log(t.t0);

                  case 17:
                  case "end":
                    return t.stop();
                }
            }, t, null, [ [ 1, 14 ] ]);
        }))();
    },
    toMyCoin: function() {
        wx.navigateTo({
            url: "/home/pages/scoreRecord/scoreRecord"
        });
    },
    toMyCard: function() {
        wx.navigateTo({
            url: "/home/pages/cardRecord/cardRecord"
        });
    },
    onShow: (e = n(r.default.mark(function e() {
        return r.default.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                this.getUserInfo(), this.getAnswer(), this.getSignList(), this.getCardInfo();

              case 4:
              case "end":
                return e.stop();
            }
        }, e, this);
    })), function() {
        return e.apply(this, arguments);
    }),
    onShareAppMessage: function() {
        return {
            title: "答题开始了 快来参加吧！",
            path: "/pages/index/index"
        };
    },
    getReason: function(e) {
        return n(r.default.mark(function t() {
            var a, n;
            return r.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return a = wx.getStorageSync("openid"), t.prev = 1, t.next = 4, s.default.errorReason({
                        openid: a,
                        type: e
                    });

                  case 4:
                    n = t.sent, wx.showToast({
                        title: n.result,
                        icon: "none",
                        duration: 1e3
                    }), t.next = 11;
                    break;

                  case 8:
                    t.prev = 8, t.t0 = t.catch(1), console.log(t.t0);

                  case 11:
                  case "end":
                    return t.stop();
                }
            }, t, null, [ [ 1, 8 ] ]);
        }))();
    },
    toDailyAnswer: function() {
        this.data.dailyActive ? wx.navigateTo({
            url: "/answer/pages/dailyAnswer/dailyAnswer"
        }) : this.getReason(2);
    },
    toPassAnswer: function() {
        this.data.passActive ? wx.navigateTo({
            url: "/answer/pages/passAnswer/passAnswer"
        }) : this.getReason(3);
    },
    toPkAnswer: function() {
        this.data.pkActive ? wx.navigateTo({
            url: "/answer/pages/pkAnswer/pkAnswer"
        }) : this.getReason(4);
    },
    toActivity: function(e) {
        var t = e.currentTarget.dataset.index, a = this.data.activities[t];
        if (a.active) switch (a.activeAnswerConfId) {
          case 2:
            wx.navigateTo({
                url: "/answer/pages/dailyAnswer/dailyAnswer?id=" + a.id + "&limit=" + a.activeAnswerConfInterval
            });
            break;

          case 3:
            wx.navigateTo({
                url: "/answer/pages/passAnswer/passAnswer?id=" + a.id + "&limit=" + a.activeAnswerConfInterval
            });
            break;

          case 4:
            wx.navigateTo({
                url: "/answer/pages/pkAnswer/pkAnswer?id=" + a.id + "&limit=" + a.activeAnswerConfInterval
            });
        } else this.getActivityReason(a.id);
    },
    getActivityReason: function(e) {
        return n(r.default.mark(function t() {
            var a, n;
            return r.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return a = wx.getStorageSync("openid"), t.prev = 1, t.next = 4, s.default.activityReason({
                        openid: a,
                        activityId: e
                    });

                  case 4:
                    n = t.sent, wx.showToast({
                        title: n.result,
                        icon: "none",
                        duration: 1e3
                    }), t.next = 11;
                    break;

                  case 8:
                    t.prev = 8, t.t0 = t.catch(1), console.log(t.t0);

                  case 11:
                  case "end":
                    return t.stop();
                }
            }, t, null, [ [ 1, 8 ] ]);
        }))();
    }
});